package cloud.xlh.service.file.adapter;

import cloud.xlh.domain.file.domain.FileSaveDomain;
import cloud.xlh.domain.file.domain.MountSettingSaveDomain;
import cloud.xlh.domain.file.domain.MountSettingUpdateDomain;
import cloud.xlh.infrastructure.file.entity.FileEntity;
import cloud.xlh.infrastructure.file.entity.MountSettingEntity;
import cloud.xlh.infrastructure.utils.CommonUtil;
import cloud.xlh.infrastructure.utils.DateUtil;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2023/8/5 11:00
 * @ Description:
 */
@Component
public class FileServiceAdapter {
    public FileEntity convertFileEntity(FileSaveDomain fileSaveDomain) {
        FileEntity fileEntity = new FileEntity();
        CommonUtil.copyPropertiesIgnoreCase(fileSaveDomain, fileEntity);
        return fileEntity;
    }

    public MountSettingEntity convertMountEntity(Object mountSettingDomain, Class aClass) {
        if (MountSettingSaveDomain.class == aClass) {
            MountSettingSaveDomain mountSettingSaveDomain = (MountSettingSaveDomain) mountSettingDomain;
            return new MountSettingEntity()
                    .setMpLocalDirPath(mountSettingSaveDomain.getMpLocalDirPath())
                    .setMpRemoteDirPath(mountSettingSaveDomain.getMpRemoteDirPath())
                    .setCreateTime(DateUtil.formatToStr(DateUtil.getCurrentDateTime() , "yyyyMMdd HH:mm:ss"))
                    .setUpdateTime(DateUtil.formatToStr(DateUtil.getCurrentDateTime() , "yyyyMMdd HH:mm:ss"));
        } else {
            MountSettingUpdateDomain mountSettingUpdateDomain = (MountSettingUpdateDomain) mountSettingDomain;
            return new MountSettingEntity()
                    .setMpLocalDirPath(mountSettingUpdateDomain.getMpRemoteDirPath())
                    .setMpRemoteDirPath(mountSettingUpdateDomain.getMpRemoteDirPath())
                    .setUpdateTime(DateUtil.getCurrentDateTime().toString());
        }
    }
}
